<!DOCTYPE html>
<html lang="en">
    <head prefix="og: https://ogp.me/ns#">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="color-scheme" content="light dark">
  
  <title>day01-MySQL基础 - Satellite</title>
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    <link rel='manifest' href='/manifest.json'>
  

  
  
  
  <meta property="og:title" content="day01-MySQL基础 - Satellite" />
  
  <meta property="og:type" content="article" />
  
  <meta property="og:url" content="http://example.com/2023/09/21/day01-MySQL%E5%9F%BA%E7%A1%80/index.html" />
  
  <meta property="og:image" content="/favicon.png" />
  
  <meta property="og:article:published_time" content="2023-09-21T02:06:58.000Z" />
  
  <meta property="og:article:author" content="John Doe" />
  
  

  
<link rel="stylesheet" href="/css/var.css">

  
<link rel="stylesheet" href="/css/main.css">

  
<link rel="stylesheet" href="/css/typography.css">

  
<link rel="stylesheet" href="/css/code-highlighting.css">

  
<link rel="stylesheet" href="/css/components.css">

  
<link rel="stylesheet" href="/css/nav.css">

  
<link rel="stylesheet" href="/css/paginator.css">

  
<link rel="stylesheet" href="/css/footer.css">

  
<link rel="stylesheet" href="/css/post-list.css">

  
  
<link rel="stylesheet" href="/css/rainbow-banner.css">

  
  
  
<link rel="stylesheet" href="/css/toc.css">

  
  
  
  
  
<link rel="stylesheet" href="/css/post.css">

  
  
  
  
  

  
<meta name="generator" content="Hexo 6.3.0"></head>
    <body
        data-color-scheme="auto"
        data-uppercase-categories="true"
        
        data-rainbow-banner="true"
        data-rainbow-banner-shown="auto"
        data-rainbow-banner-month="6"
        data-rainbow-banner-colors="#e50000,#ff8d00,#ffee00,#008121,#004cff,#760188"
        
        data-config-root="/"
        
        data-toc="true"
        data-toc-max-depth="2"
        
        
    >
        <nav id="theme-nav">
    <div class="inner">
        <a class="title" href="/">Satellite&#39;s Blog</a>
        <div class="nav-arrow"></div>
        <div class="nav-items">
            <a class="nav-item nav-item-home" href="/">Home</a>
            
            
            <a class="nav-item" href="/archives">Archives</a>
            
            
            
            <a class="nav-item" href="/about">About</a>
            
            
            
            <a class="nav-item nav-item-github nav-item-icon" href="https://github.com/Satellite2426" target="_blank" aria-label="GitHub">&nbsp;</a>
            
            
        </div>
    </div>
</nav>
        
<article class="post">
    <div class="meta">
        

        
        <div class="date" id="date">
            <span>September</span>
            <span>21,</span>
            <span>2023</span>
        </div>
        

        <h2 class="title">day01-MySQL基础</h2>
    </div>

    <div class="divider"></div>

    <div class="content">
        <h1 id="1-数据库相关概念"><a href="#1-数据库相关概念" class="headerlink" title="1. 数据库相关概念"></a>1. 数据库相关概念</h1><h2 id="1-1-数据库"><a href="#1-1-数据库" class="headerlink" title="1.1 数据库"></a>1.1 数据库</h2><ul>
<li>存储数据的仓库，数据是有组织的进行存储</li>
<li>英文: DataBase，简称 DB</li>
</ul>
<h2 id="1-2-数据库管理系统"><a href="#1-2-数据库管理系统" class="headerlink" title="1.2 数据库管理系统"></a>1.2 数据库管理系统</h2><ul>
<li>管理数据库的大型软件</li>
<li>英文:DataBase Management System，简称 DBMS</li>
</ul>
<h2 id="1-3-SQL"><a href="#1-3-SQL" class="headerlink" title="1.3 SQL"></a>1.3 SQL</h2><ul>
<li>英文: Structured Query Language，简称 SQL，结构化查询语言</li>
<li>操作关系型数据库的编程语言</li>
<li>定义操作所有关系型数据库的统一标准</li>
</ul>
<h1 id="2-MySQL-数据库"><a href="#2-MySQL-数据库" class="headerlink" title="2. MySQL 数据库"></a>2. MySQL 数据库</h1><p>本地MySQL user and password：</p>
<pre><code>root
1234
</code></pre>
<h2 id="2-1-登录"><a href="#2-1-登录" class="headerlink" title="2.1 登录"></a>2.1 登录</h2><pre><code>mysql -uroot -p123456
</code></pre>
<h2 id="2-2-MySQL数据模型"><a href="#2-2-MySQL数据模型" class="headerlink" title="2.2 MySQL数据模型"></a>2.2 MySQL数据模型</h2><h3 id="2-2-1-关系型数据库"><a href="#2-2-1-关系型数据库" class="headerlink" title="2.2.1 关系型数据库"></a>2.2.1 关系型数据库</h3><p>关系型数据库是建立在关系模型基础上的数据库，简单说，关系型数据库是由多张能互相连接的 <strong>二维表</strong> 组成的数据库</p>
<h3 id="2-2-2-优点"><a href="#2-2-2-优点" class="headerlink" title="2.2.2 优点"></a>2.2.2 优点</h3><pre><code>1.都是使用表结构，格式一致，易于维护
2.使用通用的SQL语言操作，使用方便，可用于复杂查询
3.数据存储在磁盘中，安全
</code></pre>
<h1 id="3-SQL"><a href="#3-SQL" class="headerlink" title="3. SQL"></a>3. SQL</h1><ul>
<li>英文: Structured Query Language，简称 SQL</li>
<li>结构化查询语言，一门操作关系型数据库的编程语言</li>
<li>定义操作所有关系型数据库的统一标准</li>
<li>对于同一个需求，每一种数据库操作的方式可能会存在一些不一样的地方，我们称为“方言“</li>
</ul>
<h2 id="3-1-通用语法"><a href="#3-1-通用语法" class="headerlink" title="3.1 通用语法"></a>3.1 通用语法</h2><ol>
<li><p>SQL 语可以单行或多行书写，以分号结尾</p>
</li>
<li><p>MySQL 数据库的 SQL 语句不区分大小写，关键字建议使用大写</p>
</li>
<li><p>.注释</p>
<ul>
<li>单行注释：– 注释内容 或  #注释内容(MySQL 特有)</li>
<li>多行注释：&#x2F;* 注释 *&#x2F;</li>
</ul>
</li>
</ol>
<h2 id="3-2-SQL分类"><a href="#3-2-SQL分类" class="headerlink" title="3.2 SQL分类"></a>3.2 SQL分类</h2><ul>
<li>DDL (Data Definition Language)数据定义语言，用来定义数据库对象：数据库，表，列</li>
<li>DML (Data Manipulation Language)数据操作语言，用来对数据库中表的数据进行增删改</li>
<li>DQL (Data Query Language)数据查询语言，用来查询数据库中表的记录(数据)</li>
<li>DCL (Data Control Language) 数据控制语言，用来定义数据库的访问权限和安全级别，及创建用户</li>
</ul>
<h3 id="3-2-1-DDL-–-操作数据库"><a href="#3-2-1-DDL-–-操作数据库" class="headerlink" title="3.2.1 DDL – 操作数据库"></a>3.2.1 DDL – 操作数据库</h3><h4 id="1-查询"><a href="#1-查询" class="headerlink" title="1.查询"></a>1.查询</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> databases;</span><br></pre></td></tr></table></figure>

<h4 id="2-创建"><a href="#2-创建" class="headerlink" title="2.创建"></a>2.创建</h4><ul>
<li>创建数据库</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> databases 数据库名称;</span><br></pre></td></tr></table></figure>

<ul>
<li>创建数据库(判断，如果不存在则创建)</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> database if <span class="keyword">not</span> <span class="keyword">exists</span> 数据库名称;	</span><br></pre></td></tr></table></figure>

<h4 id="3-删除"><a href="#3-删除" class="headerlink" title="3.删除"></a>3.删除</h4><ul>
<li>删除数据库</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> database 数据库名称;</span><br></pre></td></tr></table></figure>

<ul>
<li>删除数据库(判断，如果存在则删除)</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> database if <span class="keyword">exists</span> 数据库名称;</span><br></pre></td></tr></table></figure>

<h4 id="4-使用数据库"><a href="#4-使用数据库" class="headerlink" title="4.使用数据库"></a>4.使用数据库</h4><ul>
<li>查看当前使用的数据库</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> database();</span><br></pre></td></tr></table></figure>

<ul>
<li>使用数据库</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">use 数据库名称;</span><br></pre></td></tr></table></figure>

<h3 id="3-2-2-DDL-–-操作表"><a href="#3-2-2-DDL-–-操作表" class="headerlink" title="3.2.2 DDL – 操作表"></a>3.2.2 DDL – 操作表</h3><h4 id="1-查询-1"><a href="#1-查询-1" class="headerlink" title="1.查询"></a>1.查询</h4><ul>
<li>查询当前数据库下所有表名称</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> tables;	</span><br></pre></td></tr></table></figure>

<ul>
<li>查询表结构</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">desc</span> 表名称;	</span><br></pre></td></tr></table></figure>

<h4 id="2-创建-1"><a href="#2-创建-1" class="headerlink" title="2.创建"></a>2.创建</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> 表名 (</span><br><span class="line">	字段名<span class="number">1</span> 数据类型<span class="number">1</span>,</span><br><span class="line">	字段名<span class="number">2</span> 数据类型<span class="number">2</span>,</span><br><span class="line">	...</span><br><span class="line">	字段名n 数据类型n,</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：最后一行末尾，不能加逗号</p>
</blockquote>
<h4 id="3-删除和修改"><a href="#3-删除和修改" class="headerlink" title="3.删除和修改"></a>3.删除和修改</h4><ul>
<li>删除表</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> 表名;</span><br></pre></td></tr></table></figure>

<ul>
<li>删除表是判断表是否存在</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> if <span class="keyword">exists</span> 表名;	</span><br></pre></td></tr></table></figure>

<ul>
<li>修改表名</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 rename <span class="keyword">to</span> 新的表名;</span><br></pre></td></tr></table></figure>

<ul>
<li>添加一列</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 <span class="keyword">add</span> 列名 数据类型;</span><br></pre></td></tr></table></figure>

<ul>
<li>修改数据类型</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 modify 列名 数据类型;</span><br></pre></td></tr></table></figure>

<ul>
<li>修改列名和数据类型</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 change 列名 新列名 新数据类型;</span><br></pre></td></tr></table></figure>

<ul>
<li>删除列</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 <span class="keyword">drop</span> 列名;</span><br></pre></td></tr></table></figure>

<h3 id="3-2-3-DML-–-增删改"><a href="#3-2-3-DML-–-增删改" class="headerlink" title="3.2.3 DML – 增删改"></a>3.2.3 DML – 增删改</h3><p>1.给指定列添加数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名(列名<span class="number">1</span>, 列名<span class="number">2</span>, ...) <span class="keyword">values</span>(值<span class="number">1</span>, 值<span class="number">2</span>, ...);</span><br></pre></td></tr></table></figure>

<p>2.给全部列添加数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名 <span class="keyword">values</span>(值<span class="number">1</span>, 值<span class="number">2</span>, ...);</span><br></pre></td></tr></table></figure>

<p>3.批量添加数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名(列名<span class="number">1</span>, 列名<span class="number">2</span>, ...) <span class="keyword">values</span>(值<span class="number">1</span>, 值<span class="number">2</span>, ...),(值<span class="number">1</span>, 值<span class="number">2</span>, ...),(值<span class="number">1</span>, 值<span class="number">2</span>, ...)...;</span><br><span class="line"></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名 <span class="keyword">values</span>(值<span class="number">1</span>, 值<span class="number">2</span>, ...),(值<span class="number">1</span>, 值<span class="number">2</span>, ...),(值<span class="number">1</span>, 值<span class="number">2</span>, ...)...;</span><br></pre></td></tr></table></figure>

<p>4.修改数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">update</span> 表名 <span class="keyword">set</span> 列名<span class="number">1</span><span class="operator">=</span>值<span class="number">1</span>, 列名<span class="number">2</span><span class="operator">=</span>值<span class="number">2</span>,...[<span class="keyword">where</span> 条件];</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：修改语句中如果不加条件，则将所有数据都修改</p>
</blockquote>
<p>5.删除数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> 表名 [<span class="keyword">where</span> 条件];</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：删除语句中如果不加条件，则将所有的数据都删除</p>
</blockquote>
<h3 id="3-2-4-DQL-–-查询数据"><a href="#3-2-4-DQL-–-查询数据" class="headerlink" title="3.2.4 DQL – 查询数据"></a>3.2.4 DQL – 查询数据</h3><p>基础语法</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span></span><br><span class="line">	字段列表</span><br><span class="line"><span class="keyword">from</span></span><br><span class="line">	表名列表</span><br><span class="line"><span class="keyword">where</span></span><br><span class="line">	条件列表</span><br><span class="line"><span class="keyword">group</span> <span class="keyword">by</span></span><br><span class="line">	分组字段</span><br><span class="line"><span class="keyword">having</span></span><br><span class="line">	分组后条件</span><br><span class="line"><span class="keyword">order</span> <span class="keyword">by</span></span><br><span class="line">	排序字段</span><br><span class="line">limit</span><br><span class="line">	分页限定</span><br></pre></td></tr></table></figure>

<h4 id="1-基础查询"><a href="#1-基础查询" class="headerlink" title="1.基础查询"></a>1.基础查询</h4><ul>
<li>查询多个字段</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名;</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> 表名;  <span class="comment">-- 查询所有数据</span></span><br></pre></td></tr></table></figure>

<ul>
<li>去除重复记录</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">distinct</span> 字段列表 <span class="keyword">from</span> 表名;</span><br></pre></td></tr></table></figure>

<ul>
<li>起别名</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">as</span>: <span class="keyword">as</span> 也可以省略</span><br></pre></td></tr></table></figure>

<h4 id="2-条件查询"><a href="#2-条件查询" class="headerlink" title="2.条件查询"></a>2.条件查询</h4><ul>
<li>条件查询语法</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名 <span class="keyword">where</span> 条件列表;</span><br></pre></td></tr></table></figure>

<ul>
<li>条件</li>
</ul>
<table>
<thead>
<tr>
<th>符号</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>&gt;</td>
<td>大于</td>
</tr>
<tr>
<td>&lt;</td>
<td>小于</td>
</tr>
<tr>
<td>&gt;&#x3D;</td>
<td>大于等于</td>
</tr>
<tr>
<td>&lt;&#x3D;</td>
<td>小于等于</td>
</tr>
<tr>
<td>&#x3D;</td>
<td>等于</td>
</tr>
<tr>
<td>&lt;&gt;&#x2F; !&#x3D;</td>
<td>不等于</td>
</tr>
<tr>
<td>between…and…</td>
<td>在某个范围内（都包含）</td>
</tr>
<tr>
<td>in(…)</td>
<td>多选…</td>
</tr>
<tr>
<td>like 占位符</td>
<td>模糊查询 _单个任意字符 %多个任意字符</td>
</tr>
<tr>
<td>is null</td>
<td>是null</td>
</tr>
<tr>
<td>is not null</td>
<td>不是null</td>
</tr>
<tr>
<td>and &#x2F; &amp;&amp;</td>
<td>并且</td>
</tr>
<tr>
<td>or &#x2F; ||</td>
<td>或者</td>
</tr>
<tr>
<td>not &#x2F; !</td>
<td>非，不是</td>
</tr>
</tbody></table>
<h4 id="3-排序查询"><a href="#3-排序查询" class="headerlink" title="3.排序查询"></a>3.排序查询</h4><ul>
<li>排序查询的语法</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名 <span class="keyword">order</span> <span class="keyword">by</span> 排序字段名<span class="number">1</span> [排序方式<span class="number">1</span>], 排序字段名<span class="number">2</span> [排序方式<span class="number">2</span>] ...;</span><br></pre></td></tr></table></figure>

<p>排序方式：</p>
<p>​	ASC：升序排列（默认值）<br>	DESC： 降序排序</p>
<blockquote>
<p>注意：如果有多个排序条件，当前边的条件值一样时，才会根据第二条件进行排序</p>
</blockquote>
<h4 id="4-分组查询"><a href="#4-分组查询" class="headerlink" title="4.分组查询"></a>4.分组查询</h4><p><strong>聚合函数</strong></p>
<p>定义：将一列数据作为一个整体，进行纵向计算</p>
<p>聚合函数分类：</p>
<table>
<thead>
<tr>
<th>函数名</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>count(列名)</td>
<td>统计数量(一般选用不为null的列)  一般使用主键 &#x2F; *</td>
</tr>
<tr>
<td>max(列名)</td>
<td>最大值</td>
</tr>
<tr>
<td>min(列名)</td>
<td>最小值</td>
</tr>
<tr>
<td>sum(列名)</td>
<td>求和</td>
</tr>
<tr>
<td>avg(列名)</td>
<td>平均值</td>
</tr>
</tbody></table>
<p>聚合函数语法：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 聚合函数名 (列名) <span class="keyword">from</span> 表;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：null 值不参与所有聚合函数运算</p>
</blockquote>
<p><strong>分组查询语法</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名 [<span class="keyword">where</span> 分组前条件限定] <span class="keyword">group</span> <span class="keyword">by</span> 分组字段名 [<span class="keyword">having</span> 分组后条件过滤];</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：分组之后，查询的字段为聚合函数和分组字段,查询其他字段无任何意义</p>
</blockquote>
<p>where和having的区别：</p>
<p>执行时间不一样：where 是分组之前进行限定，不满足where条件，则不参与分组，而having是分组之后对结果进行过滤</p>
<p>可判断的条件不一样：where 不能对聚合函数进行判断，having 可以（having可以判断聚合函数）</p>
<p>执行顺序：where &gt; 聚合函数 &gt; having</p>
<h4 id="5-分页查询"><a href="#5-分页查询" class="headerlink" title="5.分页查询"></a>5.分页查询</h4><p>分页查询的语法</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名 limit 起始索引, 查询条目数;</span><br></pre></td></tr></table></figure>

<p>起始索引：从0开始</p>
<p>计算公式：起始索引 &#x3D; (当前页面 - 1) * 每页显示的条数</p>
<blockquote>
<p>tips：分页查询limit是MySQL数据库的方言</p>
<p>​			 Oracle分页查询使用 rownumber</p>
<p>​			 SQL server 分页查询使用 top</p>
</blockquote>

    </div>

    
    <div class="about">
        <h1>About this Post</h1>
        <div class="details">
            <p>This post is written by John Doe, licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc/4.0">CC BY-NC 4.0</a>.</p>
        </div>
        
        <p class="tags text-capitalize">
            
            <i class="icon"></i>
            <a href="/tags/Java-Web/" class="tag">#Java Web</a>
        </p>
        
    </div>
    

    <div class="container post-prev-next">
        
        <a href="/2023/09/21/day02-MySQL/" class="next">
            <div>
                <div class="text">
                    <p class="label">Next</p>
                    <h3 class="title">day02-MySQL</h3>
                </div>
            </div>
        </a>
        
        
        <a href="/2023/09/21/%E6%95%B0%E7%BB%84/" class="prev">
            <div>
                <div class="text">
                    <p class="label">Previous</p>
                    <h3 class="title">数组</>
                </div>
            </div>
        </a>
        
    </div>

    
        
        
    
</article>

        <footer>
    <div class="inner">
        <div class="links">
            
            <div class="group">
                <h2 class="title">Blog</h2>
                
                <a href="/" class="item">Blog</a>
                
                <a href="/archives" class="item">Archives</a>
                
                <a href="/tags" class="item">Tags</a>
                
                <a href="/categories" class="item">Categories</a>
                
                <a href="/about" class="item">About</a>
                
            </div>
            
            <div class="group">
                <h2 class="title">Projects</h2>
                
                <a target="_blank" rel="noopener" href="https://github.com/MrWillCom/rsa-cli" class="item">RSA CLI</a>
                
                <a target="_blank" rel="noopener" href="https://github.com/MrWillCom/hexo-theme-cupertino" class="item">Hexo Theme Cupertino</a>
                
                <a target="_blank" rel="noopener" href="https://github.com/MrWillCom/a-calendar" class="item">A Calendar</a>
                
                <a target="_blank" rel="noopener" href="https://github.com/MrWillCom/auto-mirroring-bucket" class="item">Auto Mirroring Bucket</a>
                
            </div>
            
            <div class="group">
                <h2 class="title">Me</h2>
                
                <a target="_blank" rel="noopener" href="https://github.com/Satellite2426" class="item">GitHub</a>
                
                <a href="mailto:chaoshihan2426@gmail.com" class="item">Email</a>
                
            </div>
            
        </div>
        <span>&copy; 2023 John Doe<br>Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> </span>
        
        
            <br>
            <div class="color-scheme-toggle" role="radiogroup" id="theme-color-scheme-toggle">
                <label>
                    <input type="radio" value="light">
                    <span>Light</span>
                </label>
                <label>
                    <input type="radio" value="dark">
                    <span>Dark</span>
                </label>
                <label>
                    <input type="radio" value="auto">
                    <span>Auto</span>
                </label>
            </div>
        
    </div>
</footer>


        
<script src="/js/main.js"></script>

        
        
        

        
        <script src="https://unpkg.com/scrollreveal"></script>
        <script>
            window.addEventListener('load', () => {
                ScrollReveal({ delay: 250, reset: true, easing: 'cubic-bezier(0, 0, 0, 1)' })
                ScrollReveal().reveal('.post-list-item .cover-img img')
                ScrollReveal().reveal('.post-list-item, .card, .content p img, .content .block-large img', { distance: '60px', origin: 'bottom', duration: 800 })
            })
        </script>
        
    </body>
</html>